<template>
	<view>
		<view v-if="JSON.stringify(address) === '{}'" class="address-choose-box">
			<button @click="chooseAddress" type="primary" size="mini" class="addressButton">请选择收获地址</button>
		</view>
		<view v-else @click="chooseAddress" class="address-info-box">
			<view class="row-1">
				<view class="row-1-left">
					<view class="username">
						收货人：{{address.userName}}
					</view>
				</view>
				<view class="row-1-right">
					<view class="phone">
						电话：{{address.telNumber}}
					</view>
					<uni-icons type="right" size="16"></uni-icons>
				</view>
			</view>
			<view class="row-2">
				<view class="row-2-left">
					收货地址：
				</view>
				<view class="row-2-rghit">
					{{getAddress}}
				</view>
			</view>
		</view>
		<image src="/static/cart_border@2x.png" class="address-border"></image>
	</view>
</template>
<script>
	import {
		mapMutations,
		mapState,
		mapGetters
	} from 'vuex'
	export default {
		data() {
			return {

			};
		},
		computed: {
			...mapState('user', ['address']),
			...mapGetters('user',['getAddress'])
		},
		methods: {
			...mapMutations('user', ['updateAddress']),
			async chooseAddress() {
				const res = await uni.chooseAddress().catch(error => error)
				if (res !== null && res.errMsg === "chooseAddress:ok") {
					this.updateAddress(res)
				} else {
					uni.$showMsg('获取地址失败，请重试', 1500)
				}


			}
		}
	}
</script>
<style lang="scss">
	.address-choose-box {
		display: flex;
		justify-content: center;
		align-items: center;
		height: 90px;

	}

	.address-info-box {
		padding: 5px 5px;
		height: 90px;
		display: flex;
		flex-direction: column;
		justify-content: center;

		font-size: 12px;

		.row-1 {
			margin-bottom: 10px;
			display: flex;
			justify-content: space-between;

			.row-1-right {
				display: flex;
				justify-content: space-around;
			}
		}

		.row-2 {
			display: flex;

			.row-2-left {
				display: flex;
				align-items: center;

				white-space: nowrap;
			}
		}
	}

	.address-border {
		display: block;
		width: 100%;
		height: 5px;
	}
</style>